/*
 * Countdown/countup class used to make a countdown for different things.
 * you must manually subtract from the time you actually want to get the endtime
 */

package x;

/**
 *
 * @author Omar
 */


public class Counter {

    private long beginTime = 0;
    private long endTime = 0;
    private boolean running = false;


    public void start() {
        this.beginTime = System.currentTimeMillis();
        this.running = true;
    }


    public void stop() {
        this.endTime = System.currentTimeMillis();
        this.running = false;
    }


    //elaspsed time in milliseconds
    public long getTimeMs() {
        long elapsed;
        if (running) {
             elapsed = (System.currentTimeMillis() - beginTime);
        }
        else {
            elapsed = (endTime - beginTime);
        }
        return elapsed;
    }


    //elaspsed time in seconds
    public long getTimeSecs() {
        long elapsed;
        if (running) {
            elapsed = ((System.currentTimeMillis() - beginTime) / 1000);
        }
        else {
            elapsed = ((endTime - beginTime) / 1000);
        }
        return elapsed;
    }

}


